
/**
 * @fileoverview  The stories container.
 * @author johannes.nel@gmail.com (Johan)
 * Date: 2012/03/28
 * Time: 9:51 AM
 */




goog.provide('lfpug.ui.component.StoryComponent');

goog.require('lfpug.model.Story');
goog.require('lfpug.ui.Component');
goog.require('lfpug.ui.component.TasksComponent');
goog.require('lfpug.ui.renderer.StoryRenderer');



/**
 * @constructor
 * @extends {lfpug.ui.Component}
 *
 * @param {lfpug.ui.type.Model} model
 *        The adaptor.
 *
 * @param {lfpug.ui.Renderer=} opt_renderer
 *        Optional renderer.
 */
lfpug.ui.component.StoryComponent = function(model, opt_renderer) {
  goog.base(this, model, opt_renderer);
};
goog.inherits(
    lfpug.ui.component.StoryComponent,
    lfpug.ui.Component
);


/**
 * @type {lfpug.ui.component.TasksComponent}
 */
lfpug.ui.component.StoryComponent.prototype.tasksContainer_;


/** @override */
lfpug.ui.component.StoryComponent.prototype.setDefaultRenderer = function() {
  var renderer = lfpug.ui.renderer.StoryRenderer.getInstance();
  this.setRenderer(renderer);
};


/**
 * @override
 */
lfpug.ui.component.StoryComponent.prototype.loadModelItems = function() {
  goog.base(this, 'loadModelItems');
  var model = this.getModel();
  if (!goog.isDefAndNotNull(this.tasksContainer_)) {
    this.tasksContainer_ =
        new lfpug.ui.component.TasksComponent(model.getTasks());
    this.addChild(this.tasksContainer_, true);
  }

};


/**
 * @override
 */
lfpug.ui.component.StoryComponent.prototype.unloadModelItems = function() {
  goog.base(this, 'unloadModelItems');
  if (!goog.isDefAndNotNull(this.tasksContainer_)) {
    this.tasksContainer_.dispose();
  }
};


/**
 * @override
 */
lfpug.ui.component.StoryComponent.prototype.disposeInternal = function() {
  if (!goog.isDefAndNotNull(this.tasksContainer_)) {
    this.tasksContainer_.dispose();
  }
  goog.base(this, 'disposeInternal');
};


goog.ui.registry.setDecoratorByClassName(
    lfpug.ui.Renderer.CSS_CLASS,
    function() {
      return new lfpug.ui.Component(null);
    });


lfpug.ui.ComponentFactory.register(
    lfpug.model.Story,
    function(story) {
      return new lfpug.ui.component.StoryComponent(
          /** @type {lfpug.model.Story} */(story));
    }
);

